<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="官方编号" prop="官方编号">
        <el-input
          v-model="queryParams.官方编号"
          placeholder="请输入官方编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="性别">
        <el-input
          v-model="queryParams.性别"
          placeholder="请输入性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生日期" prop="出生日期">
        <el-date-picker clearable
          v-model="queryParams.出生日期"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出生日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="净效益" prop="净效益">
        <el-input
          v-model="queryParams.净效益"
          placeholder="请输入净效益"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:yzz:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:yzz:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:yzz:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:yzz:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="yzzList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="官方编号" align="center" prop="官方编号" />
      <el-table-column label="性别" align="center" prop="性别" />
      <el-table-column label="出生日期" align="center" prop="出生日期" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.出生日期, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="净效益" align="center" prop="净效益" />
      <el-table-column label="基因组净效益可靠性" align="center" prop="基因组净效益可靠性" />
      <el-table-column label="净效益美国百分比排名" align="center" prop="净效益美国百分比排名" />
      <el-table-column label="FeedSave" align="center" prop="FeedSave" />
      <el-table-column label="RFI" align="center" prop="RFI" />
      <el-table-column label="产奶量" align="center" prop="产奶量" />
      <el-table-column label="乳脂率" align="center" prop="乳脂率" />
      <el-table-column label="乳脂量" align="center" prop="乳脂量" />
      <el-table-column label="乳蛋白率" align="center" prop="乳蛋白率" />
      <el-table-column label="乳蛋白量" align="center" prop="乳蛋白量" />
      <el-table-column label="体细胞评分" align="center" prop="体细胞评分" />
      <el-table-column label="生产寿命" align="center" prop="生产寿命" />
      <el-table-column label="存活能力" align="center" prop="存活能力" />
      <el-table-column label="女儿情期受胎率" align="center" prop="女儿情期受胎率" />
      <el-table-column label="女儿产犊难易" align="center" prop="女儿产犊难易" />
      <el-table-column label="IPI" align="center" prop="IPI" />
      <el-table-column label="体型总分" align="center" prop="体型总分" />
      <el-table-column label="基因组近交系数" align="center" prop="基因组近交系数" />
      <el-table-column label="公牛配种易产性" align="center" prop="公牛配种易产性" />
      <el-table-column label="CCR" align="center" prop="CCR" />
      <el-table-column label="青年母牛受胎率" align="center" prop="青年母牛受胎率" />
      <el-table-column label="女儿死胎率" align="center" prop="女儿死胎率" />
      <el-table-column label="公牛配种死胎率" align="center" prop="公牛配种死胎率" />
      <el-table-column label="GL" align="center" prop="GL" />
      <el-table-column label="EFC" align="center" prop="EFC" />
      <el-table-column label="单倍型" align="center" prop="单倍型" />
      <el-table-column label="肢蹄结构评分" align="center" prop="肢蹄结构评分" />
      <el-table-column label="乳房综合评分" align="center" prop="乳房综合评分" />
      <el-table-column label="体躯容量" align="center" prop="体躯容量" />
      <el-table-column label="强壮度" align="center" prop="强壮度" />
      <el-table-column label="体深" align="center" prop="体深" />
      <el-table-column label="乳用性" align="center" prop="乳用性" />
      <el-table-column label="尻角度" align="center" prop="尻角度" />
      <el-table-column label="尻宽" align="center" prop="尻宽" />
      <el-table-column label="后肢侧视" align="center" prop="后肢侧视" />
      <el-table-column label="后肢后视" align="center" prop="后肢后视" />
      <el-table-column label="蹄角度" align="center" prop="蹄角度" />
      <el-table-column label="肢蹄运动评分" align="center" prop="肢蹄运动评分" />
      <el-table-column label="前乳房附着" align="center" prop="前乳房附着" />
      <el-table-column label="后乳房高度" align="center" prop="后乳房高度" />
      <el-table-column label="RUW" align="center" prop="RUW" />
      <el-table-column label="悬韧带" align="center" prop="悬韧带" />
      <el-table-column label="乳房深度" align="center" prop="乳房深度" />
      <el-table-column label="前乳头位置" align="center" prop="前乳头位置" />
      <el-table-column label="后乳头位置" align="center" prop="后乳头位置" />
      <el-table-column label="乳头长度" align="center" prop="乳头长度" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:yzz:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:yzz:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改育种值对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="性别" prop="性别">
          <el-input v-model="form.性别" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="出生日期" prop="出生日期">
          <el-date-picker clearable
            v-model="form.出生日期"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="净效益" prop="净效益">
          <el-input v-model="form.净效益" placeholder="请输入净效益" />
        </el-form-item>
        <el-form-item label="基因组净效益可靠性" prop="基因组净效益可靠性">
          <el-input v-model="form.基因组净效益可靠性" placeholder="请输入基因组净效益可靠性" />
        </el-form-item>
        <el-form-item label="净效益美国百分比排名" prop="净效益美国百分比排名">
          <el-input v-model="form.净效益美国百分比排名" placeholder="请输入净效益美国百分比排名" />
        </el-form-item>
        <el-form-item label="FeedSave" prop="FeedSave">
          <el-input v-model="form.FeedSave" placeholder="请输入FeedSave" />
        </el-form-item>
        <el-form-item label="RFI" prop="RFI">
          <el-input v-model="form.RFI" placeholder="请输入RFI" />
        </el-form-item>
        <el-form-item label="产奶量" prop="产奶量">
          <el-input v-model="form.产奶量" placeholder="请输入产奶量" />
        </el-form-item>
        <el-form-item label="乳脂率" prop="乳脂率">
          <el-input v-model="form.乳脂率" placeholder="请输入乳脂率" />
        </el-form-item>
        <el-form-item label="乳脂量" prop="乳脂量">
          <el-input v-model="form.乳脂量" placeholder="请输入乳脂量" />
        </el-form-item>
        <el-form-item label="乳蛋白率" prop="乳蛋白率">
          <el-input v-model="form.乳蛋白率" placeholder="请输入乳蛋白率" />
        </el-form-item>
        <el-form-item label="乳蛋白量" prop="乳蛋白量">
          <el-input v-model="form.乳蛋白量" placeholder="请输入乳蛋白量" />
        </el-form-item>
        <el-form-item label="体细胞评分" prop="体细胞评分">
          <el-input v-model="form.体细胞评分" placeholder="请输入体细胞评分" />
        </el-form-item>
        <el-form-item label="生产寿命" prop="生产寿命">
          <el-input v-model="form.生产寿命" placeholder="请输入生产寿命" />
        </el-form-item>
        <el-form-item label="存活能力" prop="存活能力">
          <el-input v-model="form.存活能力" placeholder="请输入存活能力" />
        </el-form-item>
        <el-form-item label="女儿情期受胎率" prop="女儿情期受胎率">
          <el-input v-model="form.女儿情期受胎率" placeholder="请输入女儿情期受胎率" />
        </el-form-item>
        <el-form-item label="女儿产犊难易" prop="女儿产犊难易">
          <el-input v-model="form.女儿产犊难易" placeholder="请输入女儿产犊难易" />
        </el-form-item>
        <el-form-item label="IPI" prop="IPI">
          <el-input v-model="form.IPI" placeholder="请输入IPI" />
        </el-form-item>
        <el-form-item label="体型总分" prop="体型总分">
          <el-input v-model="form.体型总分" placeholder="请输入体型总分" />
        </el-form-item>
        <el-form-item label="基因组近交系数" prop="基因组近交系数">
          <el-input v-model="form.基因组近交系数" placeholder="请输入基因组近交系数" />
        </el-form-item>
        <el-form-item label="公牛配种易产性" prop="公牛配种易产性">
          <el-input v-model="form.公牛配种易产性" placeholder="请输入公牛配种易产性" />
        </el-form-item>
        <el-form-item label="CCR" prop="CCR">
          <el-input v-model="form.CCR" placeholder="请输入CCR" />
        </el-form-item>
        <el-form-item label="青年母牛受胎率" prop="青年母牛受胎率">
          <el-input v-model="form.青年母牛受胎率" placeholder="请输入青年母牛受胎率" />
        </el-form-item>
        <el-form-item label="女儿死胎率" prop="女儿死胎率">
          <el-input v-model="form.女儿死胎率" placeholder="请输入女儿死胎率" />
        </el-form-item>
        <el-form-item label="公牛配种死胎率" prop="公牛配种死胎率">
          <el-input v-model="form.公牛配种死胎率" placeholder="请输入公牛配种死胎率" />
        </el-form-item>
        <el-form-item label="GL" prop="GL">
          <el-input v-model="form.GL" placeholder="请输入GL" />
        </el-form-item>
        <el-form-item label="EFC" prop="EFC">
          <el-input v-model="form.EFC" placeholder="请输入EFC" />
        </el-form-item>
        <el-form-item label="单倍型" prop="单倍型">
          <el-input v-model="form.单倍型" placeholder="请输入单倍型" />
        </el-form-item>
        <el-form-item label="肢蹄结构评分" prop="肢蹄结构评分">
          <el-input v-model="form.肢蹄结构评分" placeholder="请输入肢蹄结构评分" />
        </el-form-item>
        <el-form-item label="乳房综合评分" prop="乳房综合评分">
          <el-input v-model="form.乳房综合评分" placeholder="请输入乳房综合评分" />
        </el-form-item>
        <el-form-item label="体躯容量" prop="体躯容量">
          <el-input v-model="form.体躯容量" placeholder="请输入体躯容量" />
        </el-form-item>
        <el-form-item label="强壮度" prop="强壮度">
          <el-input v-model="form.强壮度" placeholder="请输入强壮度" />
        </el-form-item>
        <el-form-item label="体深" prop="体深">
          <el-input v-model="form.体深" placeholder="请输入体深" />
        </el-form-item>
        <el-form-item label="乳用性" prop="乳用性">
          <el-input v-model="form.乳用性" placeholder="请输入乳用性" />
        </el-form-item>
        <el-form-item label="尻角度" prop="尻角度">
          <el-input v-model="form.尻角度" placeholder="请输入尻角度" />
        </el-form-item>
        <el-form-item label="尻宽" prop="尻宽">
          <el-input v-model="form.尻宽" placeholder="请输入尻宽" />
        </el-form-item>
        <el-form-item label="后肢侧视" prop="后肢侧视">
          <el-input v-model="form.后肢侧视" placeholder="请输入后肢侧视" />
        </el-form-item>
        <el-form-item label="后肢后视" prop="后肢后视">
          <el-input v-model="form.后肢后视" placeholder="请输入后肢后视" />
        </el-form-item>
        <el-form-item label="蹄角度" prop="蹄角度">
          <el-input v-model="form.蹄角度" placeholder="请输入蹄角度" />
        </el-form-item>
        <el-form-item label="肢蹄运动评分" prop="肢蹄运动评分">
          <el-input v-model="form.肢蹄运动评分" placeholder="请输入肢蹄运动评分" />
        </el-form-item>
        <el-form-item label="前乳房附着" prop="前乳房附着">
          <el-input v-model="form.前乳房附着" placeholder="请输入前乳房附着" />
        </el-form-item>
        <el-form-item label="后乳房高度" prop="后乳房高度">
          <el-input v-model="form.后乳房高度" placeholder="请输入后乳房高度" />
        </el-form-item>
        <el-form-item label="RUW" prop="RUW">
          <el-input v-model="form.RUW" placeholder="请输入RUW" />
        </el-form-item>
        <el-form-item label="悬韧带" prop="悬韧带">
          <el-input v-model="form.悬韧带" placeholder="请输入悬韧带" />
        </el-form-item>
        <el-form-item label="乳房深度" prop="乳房深度">
          <el-input v-model="form.乳房深度" placeholder="请输入乳房深度" />
        </el-form-item>
        <el-form-item label="前乳头位置" prop="前乳头位置">
          <el-input v-model="form.前乳头位置" placeholder="请输入前乳头位置" />
        </el-form-item>
        <el-form-item label="后乳头位置" prop="后乳头位置">
          <el-input v-model="form.后乳头位置" placeholder="请输入后乳头位置" />
        </el-form-item>
        <el-form-item label="乳头长度" prop="乳头长度">
          <el-input v-model="form.乳头长度" placeholder="请输入乳头长度" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYzz, getYzz, delYzz, addYzz, updateYzz } from "@/api/system/yzz";

export default {
  name: "Yzz",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 育种值表格数据
      yzzList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        官方编号: null,
        性别: null,
        出生日期: null,
        净效益: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询育种值列表 */
    getList() {
      this.loading = true;
      listYzz(this.queryParams).then(response => {
        this.yzzList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        官方编号: null,
        性别: null,
        出生日期: null,
        净效益: null,
        基因组净效益可靠性: null,
        净效益美国百分比排名: null,
        FeedSave: null,
        RFI: null,
        产奶量: null,
        乳脂率: null,
        乳脂量: null,
        乳蛋白率: null,
        乳蛋白量: null,
        体细胞评分: null,
        生产寿命: null,
        存活能力: null,
        女儿情期受胎率: null,
        女儿产犊难易: null,
        IPI: null,
        体型总分: null,
        基因组近交系数: null,
        公牛配种易产性: null,
        CCR: null,
        青年母牛受胎率: null,
        女儿死胎率: null,
        公牛配种死胎率: null,
        GL: null,
        EFC: null,
        单倍型: null,
        肢蹄结构评分: null,
        乳房综合评分: null,
        体躯容量: null,
        强壮度: null,
        体深: null,
        乳用性: null,
        尻角度: null,
        尻宽: null,
        后肢侧视: null,
        后肢后视: null,
        蹄角度: null,
        肢蹄运动评分: null,
        前乳房附着: null,
        后乳房高度: null,
        RUW: null,
        悬韧带: null,
        乳房深度: null,
        前乳头位置: null,
        后乳头位置: null,
        乳头长度: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.官方编号)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加育种值";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const 官方编号 = row.官方编号 || this.ids
      getYzz(官方编号).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改育种值";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.官方编号 != null) {
            updateYzz(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addYzz(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const 官方编号s = row.官方编号 || this.ids;
      this.$modal.confirm('是否确认删除育种值编号为"' + 官方编号s + '"的数据项？').then(function() {
        return delYzz(官方编号s);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/yzz/export', {
        ...this.queryParams
      }, `yzz_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
